<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>公告详情</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=none">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
</head>

<link href="https://cdn.bootcss.com/quill/1.3.6/quill.bubble.min.css" rel="stylesheet">
<style>
    /*编辑器样式修改*/

    * {
        margin: 0;
        padding: 0;
        line-height: 1.75;
    }

    body {
        font: .28rem/150% Microsoft YaHei, PingFang SC;
    }

    .ql-container {
        font-size: .34rem;
        line-height: 1.75;
    }

    #app {
        margin: .32rem;
    }

    h1 {
        font-size: .44rem;
        color: rgba(50, 50, 50, 1);
        line-height: 1.4;
    }

    .time {
        font-size: .24rem;
        color: rgba(155, 155, 155, 1);
        margin: .2rem 0;
        border-left: #212B47 1px solid;
        padding-left: 5px;
        line-height: .3rem;
    }

    .content .ql-editor {
        padding: 0;
    }

    /* 连续的空白符号得到保留,所以p标签之前大面积留空白*/
</style>
<script src="https://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<script src="../src/js/base/h5base.js"></script>
<script src="../src/js/base/baseReq.js"></script>
<script>
  $(function () {

    var path = baseReq
    var url = '/news-web/app-news/detail'
    var getUrlParam = function (name) {
      let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
      let r = window.location.search.substr(1).match(reg); //匹配目标参数
      if (r != null) return unescape(r[2]);
      return null; //返回参数值
    }
    // 函数转换时间
    var formatDate = function (time) {
      let date = new Date(time)
      let fmt = 'yyyy-MM-dd hh:mm:ss'
      if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
      }
      let o = {
        'M+': date.getMonth() + 1,
        'd+': date.getDate(),
        'h+': date.getHours(),
        'm+': date.getMinutes(),
        's+': date.getSeconds()
      }
      for (let k in o) {
        if (new RegExp(`(${k})`).test(fmt)) {
          let str = o[k] + ''
          fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : ('00' + str).substr(str.length))
        }
      }
      return fmt
    }
    if (!getUrlParam('id')) {
      alert('请传入公告id')
    }
    var noticeId = getUrlParam('id')
    $.ajax({
      url: path + url,
      type: 'post',
      dataType: 'json',
      data: JSON.stringify({
        id: noticeId,
      }),
      headers: {
        "Accept": "application/json",
        "Content-Type": "application/json"
      },
      processData: false,
      cache: false,
      success: function (data) {
        if (data.code === '200') {
          var article = data.data
          if (typeof article) {
            $('#title').text(article.title)
            $('.time').text(formatDate(article.createDate))
            $('#articleContent').html(article.bodys)
          } else {
            console.log('无数据')
          }
        } else {
          alert(data.message)
        }

      },
      error: function (err) {
        alert('服务器异常')
      }
    })
  })
</script>
<body>
<div id="app">
    <h1 id="title"></h1>
    <div class="time"></div>
    <div class="content ql-bubble ql-container">
        <div class="ql-editor" id="articleContent">
        </div>
    </div>
</div>
</body>
</html>